using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Rhizome.Contract;
using Rhizome.Contract.Diag;
using Rhizome.Contract.Visitor;
using Rhizome.Model.Validation;

namespace Rhizome.Model
{
    public sealed class CriterionState : RhizomeElement, IValidate, IStatesDiag
    {
        private ICriterion _criterion;

        public ICriterion Criterion
        {
            [DebuggerStepThrough]
            get { return _criterion; }
            set
            {
                if (_criterion == value) return;
                _criterion = value;
                var r = _criterion as RhizomeElement;
                if (r != null) r.Parent = this;
            }
        }

        public object State { get; set; }

    	#region Implementation of IValidate

    	IEnumerable<IValidationResult> IValidate.GetValidationResults()
    	{
			if (Criterion == null)
				yield return ValidationResult.CriterionIsNull;

			if (State == null) yield return ValidationResult.StateNotSet;
    	}

    	#endregion

    	#region Overrides of RhizomeElement

    	protected override IEnumerable GetLocalElements()
    	{
    		yield return Criterion;
    	}

    	#endregion

    	#region Implementation of IStatesDiag

    	IEnumerable<object> IStatesDiag.StateIds
    	{
			[DebuggerStepThrough]
    		get { yield return State; }
    	}

    	#endregion
    }
}